{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": 3
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python_defaultSpec_1596702694468",
   "display_name": "Python 3.6.4 64-bit ('base': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "subjects = [\"大学物理\",\"微积分\",\"线性代数\",\"机械制图\",\"电工电子技术\",\"程序设计基础\",\"体育\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 101\n",
    "subject_array = [np.random.choice(subjects)+np.random.choice([\"A\",\"B\",\"C\",\"D\"])+str(np.random.randint(1,10)) for x in range(n)]\n",
    "year_array = np.random.randint(2015,2021,n)\n",
    "score_array = np.random.randint(55,101,n)\n",
    "credits_array = np.random.randint(1,6,n)\n",
    "property_array = [np.random.choice([\"任选\",\"必修\",\"限选\"]) for x in range(n)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydata = {\"subject\":subject_array,\"year\":year_array,\"score\":score_array,\"credits\":credits_array,\"property\":property_array}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      subject  year  score  credits property\n0    程序设计基础A6  2019     96        1       任选\n1      机械制图D5  2018     79        4       任选\n2    程序设计基础B3  2016    100        5       必修\n3       微积分C1  2016     65        3       必修\n4       微积分A8  2015     85        5       必修\n..        ...   ...    ...      ...      ...\n96     大学物理A6  2016     82        1       限选\n97   程序设计基础D5  2016     62        2       限选\n98      微积分D6  2019     86        3       限选\n99   电工电子技术C2  2015     66        4       任选\n100  程序设计基础B4  2015     61        4       限选\n\n[101 rows x 5 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>subject</th>\n      <th>year</th>\n      <th>score</th>\n      <th>credits</th>\n      <th>property</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>程序设计基础A6</td>\n      <td>2019</td>\n      <td>96</td>\n      <td>1</td>\n      <td>任选</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>机械制图D5</td>\n      <td>2018</td>\n      <td>79</td>\n      <td>4</td>\n      <td>任选</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>程序设计基础B3</td>\n      <td>2016</td>\n      <td>100</td>\n      <td>5</td>\n      <td>必修</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>微积分C1</td>\n      <td>2016</td>\n      <td>65</td>\n      <td>3</td>\n      <td>必修</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>微积分A8</td>\n      <td>2015</td>\n      <td>85</td>\n      <td>5</td>\n      <td>必修</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>96</th>\n      <td>大学物理A6</td>\n      <td>2016</td>\n      <td>82</td>\n      <td>1</td>\n      <td>限选</td>\n    </tr>\n    <tr>\n      <th>97</th>\n      <td>程序设计基础D5</td>\n      <td>2016</td>\n      <td>62</td>\n      <td>2</td>\n      <td>限选</td>\n    </tr>\n    <tr>\n      <th>98</th>\n      <td>微积分D6</td>\n      <td>2019</td>\n      <td>86</td>\n      <td>3</td>\n      <td>限选</td>\n    </tr>\n    <tr>\n      <th>99</th>\n      <td>电工电子技术C2</td>\n      <td>2015</td>\n      <td>66</td>\n      <td>4</td>\n      <td>任选</td>\n    </tr>\n    <tr>\n      <th>100</th>\n      <td>程序设计基础B4</td>\n      <td>2015</td>\n      <td>61</td>\n      <td>4</td>\n      <td>限选</td>\n    </tr>\n  </tbody>\n</table>\n<p>101 rows × 5 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 44
    }
   ],
   "source": [
    "df = pd.DataFrame(mydata)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(4):\n",
    "    df.loc[np.random.randint(0,n),\"score\"]=\"NaN\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv(\"score.csv\",index=False,encoding=\"gbk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}